package cn.mastercom.sssvr.util;

import cn.mastercom.gui.hdfsExplorer.views.*;

import javax.swing.*;
import java.awt.*;

public class HdfsExplorer extends JFrame {
	private static final long serialVersionUID = 1L;

	private transient HdfsExplorerHelper helper;

	private TreePane treePane;

	private TablePane tablePane;

	private TabbedPane tabbedPane;

	private ToolBar toolBar;

	private GlassPane glassPane;

	public HdfsExplorer(boolean bDuli) {
		glassPane = new GlassPane();
		helper = new HdfsExplorerHelper(glassPane);
		
		initUI();
		initLayout();
		initLookAndFeel();
		
		if (bDuli)
			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		treePane.expandRootPath();
	}

	/**
	 * 初始应用程序主界面
	 */
	private void initUI() {

		treePane = new TreePane(helper);
		tablePane = new TablePane(helper);
		tabbedPane = new TabbedPane(helper);
		toolBar = new ToolBar(helper);
		
		tablePane.setFilterField(toolBar.getFilterField());
		tablePane.setFilterDetail(toolBar.getFilterDetail());

		setTitle("HDFS 管理器(" + helper.getRootUser() + ")");
		setSize(1000, 600);
		setExtendedState(Frame.MAXIMIZED_BOTH);
		setVisible(true);
		Image topicon = ResourcesDepository.getImage("images/logo2.gif");
		setIconImage(topicon);
		setGlassPane(glassPane);
		helper.setLoadingPane(glassPane);
	}

	/**
	 * 初始化主界面布局
	 */
	private void initLayout() {
		// 设置可移动分割线
		JSplitPane jSplitPane = new JSplitPane();
		jSplitPane.setOneTouchExpandable(true);// 让分割线显示出箭头
		jSplitPane.setContinuousLayout(true);// 操作箭头，重绘图形
		jSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);// 设置分割线方向
		jSplitPane.setLeftComponent(treePane);
		jSplitPane.setRightComponent(tablePane);
		jSplitPane.setDividerSize(3);// 设置分割线的宽度
		jSplitPane.setDividerLocation(300);// 设定分割线的距离左边的位置

		JSplitPane jSplitPaneTotal = new JSplitPane();
		jSplitPaneTotal.setOneTouchExpandable(true);
		jSplitPaneTotal.setContinuousLayout(true);
		jSplitPaneTotal.setOrientation(JSplitPane.VERTICAL_SPLIT);
		jSplitPaneTotal.setTopComponent(jSplitPane);
		jSplitPaneTotal.setBottomComponent(tabbedPane);
		jSplitPaneTotal.setDividerSize(3);
		jSplitPaneTotal.setDividerLocation(500);

		getContentPane().add(BorderLayout.CENTER, jSplitPaneTotal);
		// 工具栏
		getContentPane().add(BorderLayout.NORTH, toolBar);
	}

	/**
	 * 初始化主界面的字体等ui风格
	 */
	private void initLookAndFeel() {
		helper.initLookAndFeel();
	}

	public static void main(String[] args) {
		String path1 = System.getProperty("user.dir");
		System.setProperty("hadoop.home.dir", path1 + "/hadoop");
		new HdfsExplorer(true);
	}
}